/**
 * @author dragon
 * @version 1.0
 * @description java中数组的遍历
 * @date created in 2018-11-06
 */
public class ArrayFor {

    public static void main(String[] args) {
        Integer[] array = {1, 2, 4, 56, 2, 46, 23, 2, 2, 34, 6, 21, 4};
        forArray(array);
        System.out.println();
        forEachArray(array);
    }

    /**
     * 普通for循环的遍历
     *
     * @param array
     * @param <T>
     */
    public static <T> void forArray(T[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
    }

    /**
     * 普通增强for循环
     *
     * @param array
     * @param <T>
     */
    public static <T> void forEachArray(T[] array) {
        for (T t : array) {
            System.out.print(t + " ");
        }
    }
}

